<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
	    <!-- Loading Bootstrap -->
	    <link href="./Public/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
	    <!-- Loading Flat UI -->
	    <link href="./Public/Admin/Flat/dist/css/flat-ui.css" rel="stylesheet">
	    <link rel="shortcut icon" href="./Public/Admin/Flat/img/favicon.ico">
	    <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
	    <!--[if lt IE 9]>
	      <script src="dist/js/vendor/html5shiv.js"></script>
	      <script src="dist/js/vendor/respond.min.js"></script>
	    <![endif]-->
	    <script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.config.js"></script>
		<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/ueditor.all.min.js"> </script>
		<script type="text/javascript" charset="utf-8" src="Public/Admin/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	    <script type="text/javascript" src="./Public/uploadify/jquery-1.8.2.min.js"></script>
    	<script type="text/javascript" src="./Public/uploadify/jquery.uploadify.min.js"></script>
    	<link rel="stylesheet" type="text/css" href="./Public/uploadify/uploadify.css">
    	<script type="text/javascript">
    		$(function(){
    			
    			$('#goods_details').click(function(){
					$('#details').slideToggle('fast')
    			})
    			
    			$('#after_service').click(function(){
					$('#service').slideToggle('fast')
    			})
    			
    			$('#size_info').click(function(){
					$('#size').slideToggle('fast')
    			})
    			
    			var oldtid = $('#changeCate option:selected').attr('tid');

    			
    			
    			$('#changeCate').change(function(){
    				var tid = $('#changeCate option:selected').attr('tid');
    				if(tid == 0){
    					alert("顶级分类不能添加商品！");
    					$('#emptycate').attr("selected",function() { return "selected" });
						$('input[name=type_tid]').attr({value:'0' });
    					return;
    				}
					$('input[name=type_tid]').attr("value",function() { return tid });
					$.ajax({
						url:"{{U('displayTypeAttr')}}",
						type:"post",
						data:{tid : tid},
						dataType:'json',
						success:function(phpData){
							var attrstr = "";
							var specstr = "";
							$.each(phpData, function(k,v) {
								if(v.atype == 0){
									tavalue = v.tavalue.split('|');
									attrstr += "<tr class='info goodsAttr'><td width='310px'>"+v.taname+"</td><td ><select class='form-control' width='200px' name='attr["+v.taid+"]'><option value='0'>-请选择-</option>";
									$.each(tavalue,function(kk,vv){
										attrstr += "<option value="+vv+">"+vv+"</option>";
									})
									attrstr += "</select></td></tr>";
								}
								if(v.atype == 1){
									tavalue = v.tavalue.split('|');
									specstr += "<tr class='info goodsspec' ><td width='150px'>"+v.taname+"</td><td ><select class='form-control' width='400px' name=spec["+v.taid+"][tavalue][]><option value='0'>-请选择-</option>";
									$.each(tavalue,function(kk,vv){
										specstr += "<option value="+vv+">"+vv+"</option>";
									})
									specstr += "</select></td><td width='310px' style='width: 100px;'>附加价格</td><td style='width: 300px;'><input type='text' class='form-control' name=spec["+v.taid+"][add_price][]></td><td><div id ='addspec' class='btn btn-info'>添加规格</div></td></tr>";
								}
							});
							$('#attrtable').html(attrstr);
							$('#spectable').html(specstr);
						}
					});
    			})
    			
    			$('#spectable').delegate('#addspec','click',function(){
    				var aa = $(this).parents('tr').clone()
    				aa.find('#addspec').text('删除规格').attr({id:'delspec',class:'btn btn-danger'})
    				$(this).parents('tr').after(aa)
    			})
    			
    			$('#spectable').delegate('#delspec','click',function(){
    				$(this).parents('tr').remove();
    			})
    			
    			$('#listPic').delegate('#delpic','click',function(){
    				$(this).parents('li').remove();
    			})
    			
    			$('#album').delegate('#delalbum','click',function(){
    				$(this).parents('li').remove();
    			})
    			
    		})
    	</script>
	</head>
	<body>
		<form action="" method="post">
			<div class="alert alert-success">编辑商品</div>
			<div class="btn btn-primary">基本信息</div>
			<table class="table table-bordered" style="width: 1050px;">
 					<tr class="info">
 						<td>所属分类</td>
 						<td>
 							<select id="changeCate" name="category_cid" class="form-control">
 							<option value="0" id="emptycate">请选择</option>
 							{{foreach from="$cateData" value="$v"}}
							  <option value="{{$v['cid']}}" tid="{{$v['type_tid']}}" {{if value="$v['cid'] == $goodsData['category_cid']"}}selected="selected"{{endif}}>{{$v['_name']}}</option>
							{{endforeach}}
							</select>
 						</td>
 					</tr>
 					<tr class="info">
 						<td>所属品牌</td>
 						<td>
 							<select name="brand_bid" class="form-control">
 							<option value="0">请选择</option>
							{{foreach from="$brandData" value="$v"}}
							  <option value="{{$v['bid']}}" {{if value="$v['bid'] == $goodsData['brand_bid']"}}selected="selected"{{endif}}>{{$v['bname']}}</option>
						  	{{endforeach}}
							</select>
 						</td>
 					</tr>
 					<tr class="info">
 						<td>商品名称</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="gname" value="{{$goodsData['gname']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>商品编号</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="gno" value="{{$goodsData['gno']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>售卖状态</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="sale_status" value="{{$goodsData['sale_status']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>售卖提示</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="sale_tip" value="{{$goodsData['sale_tip']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>单位</td>
 						<td><input type="text" class="form-control" id="exampleInputName2"  name="unit" value="{{$goodsData['unit']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>市场价</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="market_price" value="{{$goodsData['market_price']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>促销价</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="sale_price" value="{{$goodsData['sale_price']}}"></td>
 					</tr>
 					<tr class="info">
 						<td>点击次数</td>
 						<td><input type="text" class="form-control" id="exampleInputName2" name="click_rate" value="{{$goodsData['click_rate']}}"></td>
 					</tr>
			</table>
			<div class="btn btn-danger" id="attr">商品属性</div>
			<table id="attrtable" class="table table-bordered" style="width: 1050px;">
				{{foreach from="$taData" value="$v"}}
					{{if value="$v['atype'] ==0"}}
 					<tr class="info" id="goodsAttr">
 						<td width="310px">{{$v['taname']}}</td>
 						<td >
 							<select class="form-control" width="200px" name="attr[{{$v['taid']}}]">
							  <option value="0">-请选择-</option>
 							{{foreach from="$v['tavalue']" value="$vv"}}
							  <option value="{{$vv}}" {{if value="in_array($vv,$gadataCheck)"}}selected="selected"{{endif}}>{{$vv}}</option>
							{{endforeach}}
							</select>
 						</td>
 					</tr>
 					{{endif}}
 				{{endforeach}}
			</table>
			<div class="btn btn-warning">商品规格</div>
			<table id="spectable" class="table table-bordered" style="width: 1050px;">
				{{foreach from="$taData" value="$v"}}
					{{if value="$v['atype'] == 1"}}
 					<tr class="info">
 						<td width="310px" style="width: 100px;">{{$v['taname']}}</td>
 						<td>
							<select class="form-control" width="200px" name="spec[{{$v['taid']}}][tavalue][]">
							  <option value="0">-请选择-</option>
 							{{foreach from="$v['tavalue']" value="$vv"}}
							  <option value="{{$vv}}">{{$vv}}</option>
							{{endforeach}}
							</select>
 						</td>
 						<td width="310px" style="width: 100px;">附加价格</td>
 						<td>
							<input type="text" class="form-control" name="spec[{{$v['taid']}}][add_price][]" >
 						</td>
 						<td>
 							<div id ='addspec' class='btn btn-info'>添加规格</div>
 						</td>
 					</tr>
	 					{{foreach from="$oldData" value="$value"}}
		 					{{if value="$value['type_attribute_taid'] == $v['taid']"}}
		 						<tr class="info">
			 						<td width="310px" style="width: 100px;">{{$v['taname']}}</td>
			 						<td>
										<select class="form-control" width="200px" name="spec[{{$value['type_attribute_taid']}}][tavalue][]">
										  <option value="0">-请选择-</option>
			 							{{foreach from="$v['tavalue']" value="$vv"}}
										  <option value="{{$vv}}" {{if value="$value['gavalue'] == $vv"}}selected="selected"{{endif}}>{{$vv}}</option>
										{{endforeach}}
										</select>
			 						</td>
			 						<td width="310px" style="width: 100px;">附加价格</td>
			 						<td>
										<input type="text" class="form-control" name="spec[{{$value['type_attribute_taid']}}][add_price][]" value="{{$value['add_price']}}">
			 						</td>
			 						<td>
			 							<div id ='delspec' class='btn btn-danger'>删除规格</div>
			 						</td>
	 							</tr>
		 					{{endif}}
	 					{{endforeach}}
 					{{endif}}
 				{{endforeach}}
			</table>
			<div class="btn btn-primary">列表图</div>
			<table class="table table-bordered" style="width: 1050px;">
 					<tr class="info">
 						<td width="310px" style="width: 200px;">上传图片</td>
 						<td>
 							<div lab="uploadFile">
								<!-- file表单 -->
							    <input id="f" type="file" multiple="true">
							    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
							    <script type="text/javascript">
							        $(function() {
							            $('#f').uploadify({
							                'formData'     : {//POST数据
							                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
							                },
							                'fileTypeDesc' : '上传文件',//上传描述
							                'fileTypeExts' : '*.jpg;*.png',
							                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
							                'uploader' : '{{U('upload')}}',//指定服务器上传的方法
							                'buttonText':'选择文件',
							                'fileSizeLimit' : '2000KB',
							                'uploadLimit' : 10,//上传文件数
							                'width':65,
							                'height':25,
							                'successTimeout':10,//等待服务器响应时间
							                'removeTimeout' : 0.2,//成功显示时间
							                'onUploadSuccess' : function(file, data, response) {
							                    //转为json
							                    data=$.parseJSON(data);
							                    //获得图片地址
							                    var imageUrl = data.url;
							                    var li="<li>";
							                    li += "<img  src='"+imageUrl+"'/>";
							                    li += "<input type='hidden' name='listpic[]' value='"+data.path+"'/>";
							                    li +="<div id ='delpic' class='btn btn-danger'>删除图片</div>";
							                    li += "</li>";
							                    $("#listPic ul").prepend(li);
							                }
							            });
							        });
							    </script>
							    <div id="listPic">
							        <ul>
							        	{{foreach from="$listpicData" value="$v"}}
							        	<li>
							        		<img  src="{{$v}}" alt="" />
							        		<input type="hidden" name="listpic[]"  value="{{$v}}" />
							        		<div id="delpic" class='btn btn-danger'>删除图片</div>
							        	</li>
							        	{{endforeach}}
							        </ul>
							    </div>
							</div>
 						</td>
 					</tr>
			</table>
			<div class="btn btn-info">商品图册</div>
			<table class="table table-bordered" style="width: 1050px;">
 					<tr class="info">
 						<td width="310px" style="width: 200px;">上传图片</td>
 						<td>
 							<div lab="uploadFile">
								<!-- file表单 -->
							    <input id="ff" type="file" multiple="true">
							    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
							    <script type="text/javascript">
							        $(function() {
							            $('#ff').uploadify({
							                'formData'     : {//POST数据
							                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
							                },
							                'fileTypeDesc' : '上传文件',//上传描述
							                'fileTypeExts' : '*.jpg;*.png',
							                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
							                'uploader' : '{{U('upload')}}',//指定服务器上传的方法
							                'buttonText':'选择文件',
							                'fileSizeLimit' : '2000KB',
							                'uploadLimit' : 10,//上传文件数
							                'width':65,
							                'height':25,
							                'successTimeout':10,//等待服务器响应时间
							                'removeTimeout' : 0.2,//成功显示时间
							                'onUploadSuccess' : function(file, data, response) {
							                    //转为json
							                    data=$.parseJSON(data);
							                    //获得图片地址
							                    var imageUrl = data.url;
							                    var li="<li>";
							                    li += "<img  src='"+imageUrl+"'/>";
							                    li += "<input type='hidden' name='album[]' value='"+data.path+"'/>";
							                    li +="<div id ='delalbum' class='btn btn-danger'>删除图片</div>";
							                    li += "</li>";
							                    $("#album ul").prepend(li);
							                }
							            });
							        });
							    </script>
							    <div id="album">
							        <ul>
							        	{{foreach from="$albumData" value="$v"}}
							        	<li>
							        		<img  src="{{$v}}" alt="" />
							        		<input type="hidden" name="album[]"  value="{{$v}}" />
							        		<div id="delalbum" class='btn btn-danger'>删除图片</div>
							        	</li>
							        	{{endforeach}}
							        </ul>
							    </div>
							</div>
 						</td>
 					</tr>
			</table>
			<div id="size_info" class="btn btn-success btn-block" >尺码信息</div>
			<table id="size" class="table table-bordered" style="width: 1050px;display: none;">
				<tr class="info">
					<td>
						<script id="editor3" type="text/plain" style="width:100%;height:500px;" name="size_info">{{$gdData['size_info']}}</script>
						<script>var ue = UE.getEditor('editor3');</script>
					</td>
				</tr>
			</table>
			<div id="goods_details" class="btn btn-info btn-block" style="display: block;">商品详情</div>
			<table id="details" class="table table-bordered" style="width: 1050px;display: none;" >
				<tr class="info">
					<td>
						<script id="editor2" type="text/plain" style="width:100%;height:500px;" name="goods_details" >{{$gdData['goods_details']}}</script>
						<script>var ue = UE.getEditor('editor2');</script>
					</td>
				</tr>
			</table>
			<div id="after_service" class="btn btn-danger btn-block" >售后服务</div>
			<table id="service" class="table table-bordered" style="width: 1050px;display: none;">
				<tr class="info">
					<td>
						<script id="editor1" type="text/plain" style="width:100%;height:500px;" name="after_service">{{$gdData['after_service']}}</script>
						<script>var ue = UE.getEditor('editor1');</script>
					</td>
				</tr>
			</table>
			<input type="hidden" name="type_tid" id="type_tid" value="{{$_GET['tid']}}" />
			<input type="hidden" name="gid"  value="{{$_GET['gid']}}" />
			<button class="btn btn-primary btn-lg" type="submit"> 确定 </button>
		</form>
	</body>
</html>
